﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using YArchitech.Controls;
using YArchitech.LIB;

namespace HYRElectric.WirePlace
{
	public partial class DlgSetFCHigh : System.Windows.Forms.Form
	{
		public DlgSetFCHigh()
		{
			this.InitializeComponent();
			//base.Icon = Resource.YArchitechIcon;
			this.textFcHigh.Text = "50";
			this.ReadXml();
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.textFcHigh.Text == null || this.textFcHigh.Text == "")
			{
				YJKMessageBox.Show("输入数字不能为空！");
				return;
			}
			this.SaveXml();
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void textFcHigh_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar != '\b' && (e.KeyChar < '0' || e.KeyChar > '9'))
			{
				e.Handled = true;
			}
		}

		public static int GetHighValue()
		{
			string text = Path.GetTempPath() + "DlgSetFCHigh.xml";
			if (!File.Exists(text))
			{
				return -1;
			}
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(text);
			return Convert.ToInt32(xmlDocument.SelectSingleNode("HighValue").Attributes[0].Value);
		}

		private void ReadXml()
		{
			string text = Path.GetTempPath() + "DlgSetFCHigh.xml";
			if (!File.Exists(text))
			{
				return;
			}
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(text);
			string value = xmlDocument.SelectSingleNode("HighValue").Attributes[0].Value;
			if (value != null && value != "")
			{
				this.textFcHigh.Text = value;
				return;
			}
			this.textFcHigh.Text = "50";
		}

		private void SaveXml()
		{
			string filename = Path.GetTempPath() + "DlgSetFCHigh.xml";
			XmlDocument xmlDocument = new XmlDocument();
			XmlElement xmlElement = xmlDocument.CreateElement("HighValue");
			xmlDocument.AppendChild(xmlElement);
			xmlElement.SetAttribute(DlgSetFCHigh.strFCHigh, this.textFcHigh.Text);
			xmlDocument.Save(filename);
		}

		private static string strFCHigh = "吊顶上";
	}
}
